package com.example.ex2.controller;

import com.example.ex2.common.CommonResponse;
import com.example.ex2.domain.Returninfo;
import com.example.ex2.service.serviceimpl.ReturninfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ReturninfoController {
    @Autowired
    private ReturninfoServiceImpl returninfoService;
    @GetMapping("/infos")
    public CommonResponse<List<Returninfo>> getallinfos(){
        return returninfoService.getallinfos();
    }
    @GetMapping("/returninfos")
    public CommonResponse<List<Returninfo>> getReturninfos(){
        return returninfoService.getReturninfos();
    }
    @GetMapping("/returninfos/{id}")
    public CommonResponse<Returninfo> getReturninfos(@PathVariable("id") int id){
        return returninfoService.getReturninfoByID(id);
    }

    @PostMapping ("/returninfos")
    public CommonResponse<Returninfo> addReturninfo(@RequestBody Returninfo returninfo){
        return returninfoService.addReturninfo(returninfo);
    }

    @PutMapping("/returninfos")
    public CommonResponse<Returninfo> updateReturninfo(@RequestBody Returninfo returninfo){
        return returninfoService.modifyReturninfo(returninfo);
    }

    @DeleteMapping("/returninfos/{id}")
    public CommonResponse<Returninfo> deleteReturninfo(@PathVariable("id") int id){
        return returninfoService.deleteReturninfo(id);
    }
}
